﻿Imports Fruiterie_Atwater.fruiterieAtwaterMP

Public Class profil
    Inherits Fruiterie_Atwater.Pagedb


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        PanelModif.Visible = False
        Panelmdp.Visible = False

        Dim loggedUser As New client
        loggedUser = CType(Session("client"), client)
        If Not IsPostBack Then
            If Not IsNothing(Request.QueryString.Get("mdp")) And Request.QueryString.Get("mdp") = "true" Then
                Panelmdp.Visible = True

            End If
        End If

        LblNom.Text = loggedUser.nomClient.ToString()
        LblPrenom.Text = loggedUser.prenomClient.ToString()
        LblNumRue.Text = loggedUser.noCiviqueClient.ToString()
        LblNomRue.Text = loggedUser.rueClient.ToString()
        LblCP.Text = loggedUser.codePostalClient.ToString()
        LblVille.Text = loggedUser.villeClient.ToString()
        LblTelephone.Text = loggedUser.telephoneClient.ToString()
        LblCourriel.Text = loggedUser.courrielClient.ToString()



    End Sub

    Private Sub ButtonModifProfil_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonModifProfil.Click

        PanelVue.Visible = False
        PanelModif.Visible = True


        Dim loggedUser As New client
        loggedUser = CType(Session("client"), client)

        'Données memebre user préremplis dans les textboxs
        TxtBoxNumRue.Text = loggedUser.noCiviqueClient
        TxtBoxNomRue.Text = loggedUser.rueClient
        TxtBoxCP.Text = loggedUser.codePostalClient
        TxtBoxVille.Text = loggedUser.villeClient
        TxtBoxTelephone.Text = loggedUser.telephoneClient

    End Sub


    Private Sub ButtonSoumettreProfil_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonSoumettreProfil.Click

        'Partie du traitement à améliorer
        Dim loggedUser As New client
        loggedUser = CType(HttpContext.Current.Session("client"), client)

        'Transfert des champs des textboxs vers la session client
        loggedUser.noCiviqueClient = TxtBoxNumRue.Text
        loggedUser.rueClient = TxtBoxNomRue.Text
        loggedUser.codePostalClient = TxtBoxCP.Text
        loggedUser.villeClient = TxtBoxVille.Text
        loggedUser.telephoneClient = TxtBoxTelephone.Text

        '????
        'logguedUser.noCiviqueClient = CType(TxtBoxNumRue.Text, String)

        'Enregistrement de la màj dans la BDD
        man.ModifierUtilisateur(loggedUser)
        'Enregistrement de la màj dans la session
        HttpContext.Current.Session.Add("client", loggedUser)

        'Redirection pour màj output user
        Response.Redirect("profil.aspx")

    End Sub


    Private Sub ButtonModifMdp_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonModifMdp.Click
        Dim loggedUser As New client
        loggedUser = CType(HttpContext.Current.Session("client"), client)

        loggedUser.passwordClient = TxtBoxMdp.Text

        man.ModifierUtilisateur(loggedUser)

        Response.Redirect("profil.aspx?" + TxtBoxMdp.Text)
    End Sub
End Class